<!doctype html>



  


<html class="theme-next mist use-motion" lang="zh-Hans">
<head>
  <meta charset="UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1"/>



<meta http-equiv="Cache-Control" content="no-transform" />
<meta http-equiv="Cache-Control" content="no-siteapp" />












  
  
  <link href="/lib/fancybox/source/jquery.fancybox.css?v=2.1.5" rel="stylesheet" type="text/css" />




  
  
  
  

  
    
    
  

  

  

  

  

  
    
    
    <link href="//fonts.googleapis.com/css?family=Lato:300,300italic,400,400italic,700,700italic&subset=latin,latin-ext" rel="stylesheet" type="text/css">
  






<link href="/lib/font-awesome/css/font-awesome.min.css?v=4.6.2" rel="stylesheet" type="text/css" />

<link href="/css/main.css?v=5.1.0" rel="stylesheet" type="text/css" />


  <meta name="keywords" content="ruby,rbenv,rails,rake," />








  <link rel="shortcut icon" type="image/x-icon" href="/favicon.ico?v=5.1.0" />






<meta name="description" content="开始了解RoR开始RoR之前，总想着有一个舒服的IDE环境，现在主流的就是Rubymine了，只是习惯了Netbeans对Maven项目的无侵入性，打开pom.xml就能识别工程，看到IDEA的.iml 和 .idea，Eclipse的.project 和 .classpath甚至.settings，对IDE也越来越不感冒。
在准备实际动手之前，先简单学习了一下ruby的语法，相比其他语言，基础语">
<meta property="og:type" content="article">
<meta property="og:title" content="Ruby on Rails 4 入门">
<meta property="og:url" content="http://chrisrc.me/2015/09/09/ruby-on-rails-learning-notes/index.html">
<meta property="og:site_name" content="山中，山外与俯瞰">
<meta property="og:description" content="开始了解RoR开始RoR之前，总想着有一个舒服的IDE环境，现在主流的就是Rubymine了，只是习惯了Netbeans对Maven项目的无侵入性，打开pom.xml就能识别工程，看到IDEA的.iml 和 .idea，Eclipse的.project 和 .classpath甚至.settings，对IDE也越来越不感冒。
在准备实际动手之前，先简单学习了一下ruby的语法，相比其他语言，基础语">
<meta property="og:image" content="http://chrisrc.me/images/ror_learning_notes_1.png">
<meta property="og:image" content="http://chrisrc.me/images/ror_learning_notes_dir_struct.png">
<meta property="og:image" content="http://chrisrc.me/images/ror_learning_notes_mvc.png">
<meta property="og:image" content="http://chrisrc.me/images/ror_learning_notes_mvc2.png">
<meta property="og:updated_time" content="2016-12-17T07:29:29.000Z">
<meta name="twitter:card" content="summary">
<meta name="twitter:title" content="Ruby on Rails 4 入门">
<meta name="twitter:description" content="开始了解RoR开始RoR之前，总想着有一个舒服的IDE环境，现在主流的就是Rubymine了，只是习惯了Netbeans对Maven项目的无侵入性，打开pom.xml就能识别工程，看到IDEA的.iml 和 .idea，Eclipse的.project 和 .classpath甚至.settings，对IDE也越来越不感冒。
在准备实际动手之前，先简单学习了一下ruby的语法，相比其他语言，基础语">
<meta name="twitter:image" content="http://chrisrc.me/images/ror_learning_notes_1.png">



<script type="text/javascript" id="hexo.configurations">
  var NexT = window.NexT || {};
  var CONFIG = {
    root: '/',
    scheme: 'Mist',
    sidebar: {"position":"left","display":"post"},
    fancybox: true,
    motion: true,
    duoshuo: {
      userId: '0',
      author: '博主'
    },
    algolia: {
      applicationID: '',
      apiKey: '',
      indexName: '',
      hits: {"per_page":10},
      labels: {"input_placeholder":"Search for Posts","hits_empty":"We didn't find any results for the search: ${query}","hits_stats":"${hits} results found in ${time} ms"}
    }
  };
</script>



  <link rel="canonical" href="http://chrisrc.me/2015/09/09/ruby-on-rails-learning-notes/"/>





  <title> Ruby on Rails 4 入门 | 山中，山外与俯瞰 </title>
</head>

<body itemscope itemtype="http://schema.org/WebPage" lang="zh-Hans">

  










  
  
    
  

  <div class="container one-collumn sidebar-position-left page-post-detail ">
    <div class="headband"></div>

    <header id="header" class="header" itemscope itemtype="http://schema.org/WPHeader">
      <div class="header-inner"><div class="site-meta ">
  

  <div class="custom-logo-site-title">
    <a href="/"  class="brand" rel="start">
      <span class="logo-line-before"><i></i></span>
      <span class="site-title">山中，山外与俯瞰</span>
      <span class="logo-line-after"><i></i></span>
    </a>
  </div>
  <p class="site-subtitle">一次永不停止的探索之旅</p>
</div>

<div class="site-nav-toggle">
  <button>
    <span class="btn-bar"></span>
    <span class="btn-bar"></span>
    <span class="btn-bar"></span>
  </button>
</div>

<nav class="site-nav">
  

  
    <ul id="menu" class="menu">
      
        
        <li class="menu-item menu-item-home">
          <a href="/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-home"></i> <br />
            
            首页
          </a>
        </li>
      
        
        <li class="menu-item menu-item-dcos">
          <a href="/dcos" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-book"></i> <br />
            
            DC/OS
          </a>
        </li>
      
        
        <li class="menu-item menu-item-categories">
          <a href="/categories" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-th"></i> <br />
            
            分类
          </a>
        </li>
      
        
        <li class="menu-item menu-item-about">
          <a href="/about" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-user"></i> <br />
            
            关于
          </a>
        </li>
      
        
        <li class="menu-item menu-item-archives">
          <a href="/archives" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-archive"></i> <br />
            
            归档
          </a>
        </li>
      
        
        <li class="menu-item menu-item-tags">
          <a href="/tags" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-tags"></i> <br />
            
            标签
          </a>
        </li>
      

      
        <li class="menu-item menu-item-search">
          
            <a href="javascript:;" class="st-search-show-outputs">
          
            
              <i class="menu-item-icon fa fa-search fa-fw"></i> <br />
            
            搜索
          </a>
        </li>
      
    </ul>
  

  
    <div class="site-search">
      
  <form class="site-search-form">
  <input type="text" id="st-search-input" class="st-search-input st-default-search-input" />
</form>

<script type="text/javascript">
  (function(w,d,t,u,n,s,e){w['SwiftypeObject']=n;w[n]=w[n]||function(){
    (w[n].q=w[n].q||[]).push(arguments);};s=d.createElement(t);
    e=d.getElementsByTagName(t)[0];s.async=1;s.src=u;e.parentNode.insertBefore(s,e);
  })(window,document,'script','//s.swiftypecdn.com/install/v2/st.js','_st');

  _st('install', 'R9GcmhBwxpsAGLNCsquZ','2.0.0');
</script>



    </div>
  
</nav>



 </div>
    </header>

    <main id="main" class="main">
      <div class="main-inner">
        <div class="content-wrap">
          <div id="content" class="content">
            

  <div id="posts" class="posts-expand">
    

  

  
  
  

  <article class="post post-type-normal " itemscope itemtype="http://schema.org/Article">
  <link itemprop="mainEntityOfPage" href="http://chrisrc.me/2015/09/09/ruby-on-rails-learning-notes/">

  <span style="display:none" itemprop="author" itemscope itemtype="http://schema.org/Person">
    <meta itemprop="name" content="chrisrc">
    <meta itemprop="description" content="">
    <meta itemprop="image" content="/images/avatar.gif">
  </span>

  <span style="display:none" itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
    <meta itemprop="name" content="山中，山外与俯瞰">
    <span style="display:none" itemprop="logo" itemscope itemtype="http://schema.org/ImageObject">
      <img style="display:none;" itemprop="url image" alt="山中，山外与俯瞰" src="">
    </span>
  </span>

    
      <header class="post-header">

        
        
          <h1 class="post-title" itemprop="name headline">
            
            
              
                Ruby on Rails 4 入门
              
            
          </h1>
        

        <div class="post-meta">
          <span class="post-time">
            
              <span class="post-meta-item-icon">
                <i class="fa fa-calendar-o"></i>
              </span>
              <span class="post-meta-item-text">发表于</span>
              <time title="Post created" itemprop="dateCreated datePublished" datetime="2015-09-09T14:06:21+08:00">
                2015-09-09
              </time>
            

            

            
          </span>

          
            <span class="post-category" >
              <span class="post-meta-divider">|</span>
              <span class="post-meta-item-icon">
                <i class="fa fa-folder-o"></i>
              </span>
              <span class="post-meta-item-text">分类于</span>
              
                <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
                  <a href="/categories/Ruby/" itemprop="url" rel="index">
                    <span itemprop="name">Ruby</span>
                  </a>
                </span>

                
                
              
            </span>
          

          
            
              <span class="post-comments-count">
                <span class="post-meta-divider">|</span>
                <a href="/2015/09/09/ruby-on-rails-learning-notes/#comments" itemprop="discussionUrl">
                  <span class="post-comments-count ds-thread-count" data-thread-key="2015/09/09/ruby-on-rails-learning-notes/" itemprop="commentCount"></span>
                </a>
              </span>
            
          

          

          
          

          

          

        </div>
      </header>
    


    <div class="post-body" itemprop="articleBody">

      
      

      
        <h2 id="开始了解RoR"><a href="#开始了解RoR" class="headerlink" title="开始了解RoR"></a>开始了解RoR</h2><p>开始RoR之前，总想着有一个<br>舒服的IDE环境，现在主流的就是Rubymine了，只是习惯了Netbeans对Maven项目的无侵入性，打开pom.xml就能识别工程，看到IDEA的.iml 和 .idea，<br>Eclipse的.project 和 .classpath甚至.settings，对IDE也越来越不感冒。</p>
<p>在准备实际动手之前，先简单学习了一下ruby的语法，相比其他语言，基础语法规则确实简单不少。</p>
<a id="more"></a>
<h2 id="准备RoR开发环境"><a href="#准备RoR开发环境" class="headerlink" title="准备RoR开发环境"></a>准备RoR开发环境</h2><ul>
<li>操作系统 openSUSE</li>
<li>安装Ruby，本文使用2.2.2版本（通过rbenv管理）</li>
<li>安装rails，本文使用4.2.4版本</li>
</ul>
<p><strong>提示: RoR环境可参考前文 <a href="/2015-04-28/ruby-rbenv-switch-ruby-version">通过rbenv切换Ruby版本</a></strong></p>
<h2 id="开始示例"><a href="#开始示例" class="headerlink" title="开始示例"></a>开始示例</h2><p><strong>提示: 本文学习示例及部分图例来自<a href="http://book.douban.com/subject/1416743/" target="_blank" rel="external">《Agile Web Development with Rails 4》</a>一书</strong></p>
<h3 id="创建项目工程"><a href="#创建项目工程" class="headerlink" title="创建项目工程"></a>创建项目工程</h3><p>在<strong>～/Workspace</strong>目录下执行命令操作：</p>
<p><code>rails new demo</code></p>
<p>如果一切正常，demo目录下的rails项目骨架创建成功。</p>
<p><img src="/images/ror_learning_notes_1.png" alt="rails demo proj"></p>
<h3 id="检查项目是否正确创建"><a href="#检查项目是否正确创建" class="headerlink" title="检查项目是否正确创建"></a>检查项目是否正确创建</h3><p>通过<code>rake about</code>命令校验项目是否正确创建：<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div></pre></td><td class="code"><pre><div class="line">About your application&apos;s environment</div><div class="line">Rails version             4.2.4</div><div class="line">Ruby version              2.2.2-p95 (x86_64-linux)</div><div class="line">RubyGems version          2.4.5</div><div class="line">Rack version              1.6.4</div><div class="line">JavaScript Runtime        therubyracer (V8)</div><div class="line">Middleware                Rack::Sendfile, ActionDispatch::Static, Rack::Lock, ......</div><div class="line">Application root          /deepin/chrisrc/Workspace/RubyProjects/demo</div><div class="line">Environment               development</div><div class="line">Database adapter          sqlite3</div><div class="line">Database schema version   0</div></pre></td></tr></table></figure></p>
<h3 id="运行项目"><a href="#运行项目" class="headerlink" title="运行项目"></a>运行项目</h3><p>通过命令<br><code>rails server</code><br>启动服务器：</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div></pre></td><td class="code"><pre><div class="line">=&gt; Booting WEBrick</div><div class="line">=&gt; Rails 4.2.4 application starting in development on http://localhost:3000</div><div class="line">=&gt; Run `rails server -h` for more startup options</div><div class="line">=&gt; Ctrl-C to shutdown server</div><div class="line">[2015-09-09 14:39:02] INFO  WEBrick 1.3.1</div><div class="line">[2015-09-09 14:39:02] INFO  ruby 2.2.2 (2015-04-13) [x86_64-linux]</div><div class="line">[2015-09-09 14:39:02] INFO  WEBrick::HTTPServer#start: pid=7158 port=3000</div></pre></td></tr></table></figure>
<p>就这么简单，一个Web工程已经就绪。访问 <a href="http://localhost:3000" target="_blank" rel="external">http://localhost:3000</a> 查看运行结果。</p>
<h2 id="分析示例工程"><a href="#分析示例工程" class="headerlink" title="分析示例工程"></a>分析示例工程</h2><p><strong>小插曲</strong>，在学习RoR之前，一直在用基于Scala的Play2框架，此时，打开Rails的项目结构，忍不住吐槽，Rails就是另一个Play2嘛，<br>又一想不对，Rails是在Play2之前的，Play2是照搬了Rails啊，关于Play2框架，请参考<a href="/2015-03-03/scala-play2-intro">Scala技术栈——Play2框架简介</a>。</p>
<p>通过下面Rails的项目结构可以看出，Rails也是标准的MVC结构，如果你对HTTP有足够了解，可以看出，直接架设在HTTP之上的MVC，<br>结构非常简单，清晰。</p>
<p><img src="/images/ror_learning_notes_dir_struct.png" alt="rails demo proj"></p>
<h3 id="Rails中的MVC"><a href="#Rails中的MVC" class="headerlink" title="Rails中的MVC"></a>Rails中的MVC</h3><p>下面看Rails提供的一个命令：<br><code>rails generate controller Say hello goodbye</code></p>
<p>在命令行执行该命令后的控制台输出：<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div><div class="line">13</div><div class="line">14</div><div class="line">15</div><div class="line">16</div><div class="line">17</div><div class="line">18</div></pre></td><td class="code"><pre><div class="line">create app/controllers/say_controller.rb</div><div class="line">route get &quot;say/goodbye&quot;</div><div class="line">route get &quot;say/hello&quot;</div><div class="line">invoke erb</div><div class="line">create app/views/say</div><div class="line">create app/views/say/hello.html.erb</div><div class="line">create app/views/say/goodbye.html.erb</div><div class="line">invoke test_unit</div><div class="line">create test/controllers/say_controller_test.rb</div><div class="line">invoke helper</div><div class="line">create app/helpers/say_helper.rb</div><div class="line">invoke test_unit</div><div class="line">create test/helpers/say_helper_test.rb</div><div class="line">invoke assets</div><div class="line">invoke coffee</div><div class="line">create app/assets/javascripts/say.js.coffee</div><div class="line">invoke scss</div><div class="line">create app/assets/stylesheets/say.css.scss</div></pre></td></tr></table></figure></p>
<p>从输出可以看出，这条命令创建了一个Controller：<code>say_controller.rb</code>；定义了两个路由<code>say/hello</code> 和 <code>say/goodbye</code>；<br>创建了两个view分别对应两个路由<code>hello.html.erb</code> 和 <code>goodbye.html.erb</code>。</p>
<p>具体执行逻辑是：<br>**请求 <a href="http://host/say/hello" target="_blank" rel="external">http://host/say/hello</a>  </p>
<p>—-路由解析—-</p>
<p>say_controller.rb  </p>
<p>—-定义的hello方法处理（Model在此处理）——</p>
<p>hello.html.erb</p>
<p>—-响应输出。**</p>
<p>如下两幅图可以比较清晰的展示出Rails的MVC概念：<br><img src="/images/ror_learning_notes_mvc.png" alt="rails demo proj"><br><img src="/images/ror_learning_notes_mvc2.png" alt="rails demo proj"></p>
<h3 id="Rails中的Model"><a href="#Rails中的Model" class="headerlink" title="Rails中的Model"></a>Rails中的Model</h3><p>Rails的数据处理层使用ORM，<strong>Active Record</strong> 是Rails的MVC框架的模型基础。</p>
<h3 id="Rails中的View"><a href="#Rails中的View" class="headerlink" title="Rails中的View"></a>Rails中的View</h3><p>Rails的展现层使用 <strong>Embedded Ruby（ERB）</strong> 模板技术。</p>
<h3 id="Rails中的Controller"><a href="#Rails中的Controller" class="headerlink" title="Rails中的Controller"></a>Rails中的Controller</h3><p>Rails中的Controller控制路由，响应请求；处理缓存，控制会话，管理扩展模块。</p>
<h2 id="结论"><a href="#结论" class="headerlink" title="结论"></a>结论</h2><p>RoR框架再结合Ruby的简单特性，成为Web应用快速开发的强大武器是不为过的。J2EE中的JSP/Servlet技术为了专注业务而<br>过度的封装了HTTP，这也导致其自由定制的能力受到限制；同样，为了专注架构的灵活性而分层过度，这也导致了层与层间的<br>粘合随框架的不同，其易用性和性能各有优劣。</p>

      
    </div>

    <div>
      
        

      
    </div>

    <div>
      
        

      
    </div>


    <footer class="post-footer">
      
        <div class="post-tags">
          
            <a href="/tags/ruby/" rel="tag"># ruby</a>
          
            <a href="/tags/rbenv/" rel="tag"># rbenv</a>
          
            <a href="/tags/rails/" rel="tag"># rails</a>
          
            <a href="/tags/rake/" rel="tag"># rake</a>
          
        </div>
      

      
        <div class="post-nav">
          <div class="post-nav-next post-nav-item">
            
              <a href="/2015/09/06/linux-broadcom-driver-for-kernel-4/" rel="next" title="Broadcom Wireless Driver for Linux Kernel 4.0">
                <i class="fa fa-chevron-left"></i> Broadcom Wireless Driver for Linux Kernel 4.0
              </a>
            
          </div>

          <span class="post-nav-divider"></span>

          <div class="post-nav-prev post-nav-item">
            
              <a href="/2015/09/11/the-reactive-menifesto/" rel="prev" title="活性系统宣言(The Reactive Manifesto)">
                活性系统宣言(The Reactive Manifesto) <i class="fa fa-chevron-right"></i>
              </a>
            
          </div>
        </div>
      

      
      
    </footer>
  </article>



    <div class="post-spread">
      
        <div class="ds-share flat" data-thread-key="2015/09/09/ruby-on-rails-learning-notes/"
     data-title="Ruby on Rails 4 入门"
     data-content=""
     data-url="http://chrisrc.me/2015/09/09/ruby-on-rails-learning-notes/">
  <div class="ds-share-inline">
    <ul  class="ds-share-icons-16">

      <li data-toggle="ds-share-icons-more"><a class="ds-more" href="javascript:void(0);">分享到：</a></li>
      <li><a class="ds-weibo" href="javascript:void(0);" data-service="weibo">微博</a></li>
      <li><a class="ds-qzone" href="javascript:void(0);" data-service="qzone">QQ空间</a></li>
      <li><a class="ds-qqt" href="javascript:void(0);" data-service="qqt">腾讯微博</a></li>
      <li><a class="ds-wechat" href="javascript:void(0);" data-service="wechat">微信</a></li>

    </ul>
    <div class="ds-share-icons-more">
    </div>
  </div>
</div>
      
    </div>
  </div>


          </div>
          


          
  <div class="comments" id="comments">
    
      <div class="ds-thread" data-thread-key="2015/09/09/ruby-on-rails-learning-notes/"
           data-title="Ruby on Rails 4 入门" data-url="http://chrisrc.me/2015/09/09/ruby-on-rails-learning-notes/">
      </div>
    
  </div>


        </div>
        
          
  
  <div class="sidebar-toggle">
    <div class="sidebar-toggle-line-wrap">
      <span class="sidebar-toggle-line sidebar-toggle-line-first"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-middle"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-last"></span>
    </div>
  </div>

  <aside id="sidebar" class="sidebar">
    <div class="sidebar-inner">

      

      
        <ul class="sidebar-nav motion-element">
          <li class="sidebar-nav-toc sidebar-nav-active" data-target="post-toc-wrap" >
            文章目录
          </li>
          <li class="sidebar-nav-overview" data-target="site-overview">
            站点概览
          </li>
        </ul>
      

      <section class="site-overview sidebar-panel">
        <div class="site-author motion-element" itemprop="author" itemscope itemtype="http://schema.org/Person">
          <img class="site-author-image" itemprop="image"
               src="/images/avatar.gif"
               alt="chrisrc" />
          <p class="site-author-name" itemprop="name">chrisrc</p>
          <p class="site-description motion-element" itemprop="description"></p>
        </div>
        <nav class="site-state motion-element">
          <div class="site-state-item site-state-posts">
            <a href="/archives">
              <span class="site-state-item-count">69</span>
              <span class="site-state-item-name">日志</span>
            </a>
          </div>

          
            <div class="site-state-item site-state-categories">
              <a href="/categories">
                <span class="site-state-item-count">21</span>
                <span class="site-state-item-name">分类</span>
              </a>
            </div>
          

          
            <div class="site-state-item site-state-tags">
              <a href="/tags">
                <span class="site-state-item-count">162</span>
                <span class="site-state-item-name">标签</span>
              </a>
            </div>
          

        </nav>

        

        <div class="links-of-author motion-element">
          
            
              <span class="links-of-author-item">
                <a href="https://github.com/christtrc" target="_blank" title="GitHub">
                  
                    <i class="fa fa-fw fa-github"></i>
                  
                  GitHub
                </a>
              </span>
            
              <span class="links-of-author-item">
                <a href="https://twitter.com/chrisrc" target="_blank" title="Twitter">
                  
                    <i class="fa fa-fw fa-twitter"></i>
                  
                  Twitter
                </a>
              </span>
            
          
        </div>

        
        
          <div class="cc-license motion-element" itemprop="license">
            <a href="https://creativecommons.org/licenses/by-nc-sa/4.0/" class="cc-opacity" target="_blank">
              <img src="/images/cc-by-nc-sa.svg" alt="Creative Commons" />
            </a>
          </div>
        

        
        

        


      </section>

      
      <!--noindex-->
        <section class="post-toc-wrap motion-element sidebar-panel sidebar-panel-active">
          <div class="post-toc">

            
              
            

            
              <div class="post-toc-content"><ol class="nav"><li class="nav-item nav-level-2"><a class="nav-link" href="#开始了解RoR"><span class="nav-number">1.</span> <span class="nav-text">开始了解RoR</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#准备RoR开发环境"><span class="nav-number">2.</span> <span class="nav-text">准备RoR开发环境</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#开始示例"><span class="nav-number">3.</span> <span class="nav-text">开始示例</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#创建项目工程"><span class="nav-number">3.1.</span> <span class="nav-text">创建项目工程</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#检查项目是否正确创建"><span class="nav-number">3.2.</span> <span class="nav-text">检查项目是否正确创建</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#运行项目"><span class="nav-number">3.3.</span> <span class="nav-text">运行项目</span></a></li></ol></li><li class="nav-item nav-level-2"><a class="nav-link" href="#分析示例工程"><span class="nav-number">4.</span> <span class="nav-text">分析示例工程</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#Rails中的MVC"><span class="nav-number">4.1.</span> <span class="nav-text">Rails中的MVC</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#Rails中的Model"><span class="nav-number">4.2.</span> <span class="nav-text">Rails中的Model</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#Rails中的View"><span class="nav-number">4.3.</span> <span class="nav-text">Rails中的View</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#Rails中的Controller"><span class="nav-number">4.4.</span> <span class="nav-text">Rails中的Controller</span></a></li></ol></li><li class="nav-item nav-level-2"><a class="nav-link" href="#结论"><span class="nav-number">5.</span> <span class="nav-text">结论</span></a></li></ol></div>
            

          </div>
        </section>
      <!--/noindex-->
      

    </div>
  </aside>


        
      </div>
    </main>

    <footer id="footer" class="footer">
      <div class="footer-inner">
        <div class="copyright" >
  
  &copy;  2015 - 
  <span itemprop="copyrightYear">2017</span>
  <span class="with-love">
    <i class="fa fa-heart"></i>
  </span>
  <span class="author" itemprop="copyrightHolder">
     
      <a href="mailto:chrisrc@qq.com">chrisrc</a> 
    
  </span>
  <span class="author"> &nbsp; QQ: 58122705 </span>
</div>


<div class="powered-by">
  由 <a class="theme-link" href="https://hexo.io">Hexo</a> 强力驱动
</div>

<div class="theme-info">
  主题 -
  <a class="theme-link" href="https://github.com/iissnan/hexo-theme-next">
    NexT.Mist
  </a>
</div>


        

        
      </div>
    </footer>

    <div class="back-to-top">
      <i class="fa fa-arrow-up"></i>
    </div>
  </div>

  

<script type="text/javascript">
  if (Object.prototype.toString.call(window.Promise) !== '[object Function]') {
    window.Promise = null;
  }
</script>









  



  
  <script type="text/javascript" src="/lib/jquery/index.js?v=2.1.3"></script>

  
  <script type="text/javascript" src="/lib/fastclick/lib/fastclick.min.js?v=1.0.6"></script>

  
  <script type="text/javascript" src="/lib/jquery_lazyload/jquery.lazyload.js?v=1.9.7"></script>

  
  <script type="text/javascript" src="/lib/velocity/velocity.min.js?v=1.2.1"></script>

  
  <script type="text/javascript" src="/lib/velocity/velocity.ui.min.js?v=1.2.1"></script>

  
  <script type="text/javascript" src="/lib/fancybox/source/jquery.fancybox.pack.js?v=2.1.5"></script>


  


  <script type="text/javascript" src="/js/src/utils.js?v=5.1.0"></script>

  <script type="text/javascript" src="/js/src/motion.js?v=5.1.0"></script>



  
  

  
  <script type="text/javascript" src="/js/src/scrollspy.js?v=5.1.0"></script>
<script type="text/javascript" src="/js/src/post-details.js?v=5.1.0"></script>



  


  <script type="text/javascript" src="/js/src/bootstrap.js?v=5.1.0"></script>



  

  
    
  

  <script type="text/javascript">
    var duoshuoQuery = {short_name:"chrisrc"};
    (function() {
      var ds = document.createElement('script');
      ds.type = 'text/javascript';ds.async = true;
      ds.id = 'duoshuo-script';
      ds.src = (document.location.protocol == 'https:' ? 'https:' : 'http:') + '//static.duoshuo.com/embed.js';
      ds.charset = 'UTF-8';
      (document.getElementsByTagName('head')[0]
      || document.getElementsByTagName('body')[0]).appendChild(ds);
    })();
  </script>

  
    
    
    <script src="/lib/ua-parser-js/dist/ua-parser.min.js?v=0.7.9"></script>
    <script src="/js/src/hook-duoshuo.js"></script>
  








  
  

  

  

  
<script>
(function(){
    var bp = document.createElement('script');
    var curProtocol = window.location.protocol.split(':')[0];
    if (curProtocol === 'https') {
        bp.src = 'https://zz.bdstatic.com/linksubmit/push.js';        
    }
    else {
        bp.src = 'http://push.zhanzhang.baidu.com/push.js';
    }
    var s = document.getElementsByTagName("script")[0];
    s.parentNode.insertBefore(bp, s);
})();
</script>


  
<script>
(function(){
   var src = (document.location.protocol == "http:") ? "http://js.passport.qihucdn.com/11.0.1.js?ed903ab05fbc5fa64d95e4bfbf3d3a04":"https://jspassport.ssl.qhimg.com/11.0.1.js?ed903ab05fbc5fa64d95e4bfbf3d3a04";
   document.write('<script src="' + src + '" id="sozz"><\/script>');
})();
</script>

  


</body>
</html>
